import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import LayerCesiumMap from '@/layout/LayerCesiumMap'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/bigScreen',
    component: () => import('@/views/dx-big-screen/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: LayerCesiumMap,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      },
      {
        path: 'project',
        component: () => import('@/views/dx-data-project/index'),
        name: 'Project',
        meta: { title: '项目', icon: 'dashboard', affix: true }
      },
    ]
  },
  // 监测数据
  {
    path: '/monitoring',
    component: LayerCesiumMap,
    redirect: '/monitoring/theMonitoring',
    name: 'Monitoring',
    meta: {
      title: '监测数据', icon: 'documentation'
    },
    children: [
      {
        path: 'theMonitoring',
        component: () => import('@/views/dx-monitoring/index'),
        name: 'TheMonitoring',
        meta: { title: '监测菜单', icon: 'dashboard' },
        children: [
          {
            path: 'monitoringMenu',
            component: () => import('@/views/dx-monitoring/MenuLists'),
            name: 'MonitoringMenu',
            meta: { title: '监测导航', icon: 'dashboard', affix: true }
          },
          {
            path: 'monitoringDisplay',
            component: () => import('@/views/dx-monitoring/DataDisplay'),
            name: 'MonitoringDisplay',
            meta: { title: '监测列表', icon: 'dashboard', affix: true }
          },
          {
            path: 'monitoringDetail/:type/:id',
            component: () => import('@/views/dx-monitoring/DataDetail'),
            name: 'MonitoringDetail',
            meta: { title: '监测详情', icon: 'dashboard', affix: true }
          },
          {
            path: 'monitoringForm/:type/:id',
            component: () => import('@/views/dx-monitoring/DataForm'),
            name: 'MonitoringForm',
            meta: { title: '监测增改', icon: 'dashboard', affix: true }
          }
        ]
      }
    ]
  },

  // 地质模型
  {
    path: '/geological',
    component: LayerCesiumMap,
    redirect: '/geological/theGeological',
    name: 'Geological',
    meta: {
      title: '地质模型', icon: 'documentation'
    },
    children: [
      {
        path: 'theGeological',
        component: () => import('@/views/dx-geological/index'),
        name: 'TheGeological',
        meta: { title: '地质模型菜单', icon: 'dashboard' },
        children: [
          {
            path: 'geologicalMenu',
            component: () => import('@/views/dx-geological/MenuLists'),
            name: 'GeologicalMenu',
            meta: { title: '模型导航', icon: 'dashboard', affix: true }
          },
          {
            path: 'geologicalDisplay',
            component: () => import('@/views/dx-geological/DataDisplay'),
            name: 'GeologicalDisplay',
            meta: { title: '地质列表', icon: 'dashboard', affix: true }
          },
          {
            path: 'geologicalDetail/:type/:id',
            component: () => import('@/views/dx-geological/DataDetail'),
            name: 'GeologicalDetail',
            meta: { title: '地质详情', icon: 'dashboard', affix: true }
          },
          {
            path: 'geologicalForm/:type/:id',
            component: () => import('@/views/dx-geological/DataForm'),
            name: 'GeologicalForm',
            meta: { title: '地质表单', icon: 'dashboard', affix: true }
          }
        ]
      }
    ]
  },

  // 系统管理
  {
    path: '/system',
    component: LayerCesiumMap,
    redirect: '/system/theSystem',
    name: 'System',
    meta: {
      title: '系统管理', icon: 'documentation'
    },
    children: [
      {
        path: 'theSystem',
        component: () => import('@/views/dx-system/index'),
        name: 'TheSystem',
        meta: { title: '系统菜单', icon: 'dashboard' },
        children: [
          {
            path: 'systemMenu',
            component: () => import('@/views/dx-system/MenuLists'),
            name: 'SystemMenu',
            meta: { title: '系统导航', icon: 'dashboard', affix: true }
          },
          {
            path: 'systemDisplay',
            component: () => import('@/views/dx-system/DataDisplay'),
            name: 'SystemDisplay',
            meta: { title: '系统数据列表', icon: 'dashboard', affix: true }
          },
          {
            path: 'systemDetail/:type/:id',
            component: () => import('@/views/dx-system/DataDetail'),
            name: 'SystemDetail',
            meta: { title: '系统数据详情', icon: 'dashboard', affix: true }
          },
          {
            path: 'systemForm/:type/:id',
            component: () => import('@/views/dx-system/DataForm'),
            name: 'SystemForm',
            meta: { title: '系统增改', icon: 'dashboard', affix: true }
          }
        ]
      }
    ]
  }
]


export const asyncRoutes = [
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  base: '/3Dsystem/',
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
